import { useEffect } from "react";
import { BrowserRouter, Route, Router, Routes } from "react-router-dom";
import { useDispatch } from "react-redux";
import { adminSlice } from "./redux";
import Login from "./views/Login/Login";
import Layout from "./views/Layout/Layout";
import Role from "./views/Role/Role";
import Admin from "./views/Admin/Admin";
import Mine from "./views/Admin/Mine";
import UpdatePwd from "./views/Admin/UpdatePwd";
import { $getOne } from "./api/adminApi";
import Type from "./views/Type/Type";
import Room from "./views/Room/Room";
import Guest from "./views/Guest/Guest";
import TotalPrice from "./views/Type/TotalPrice";
function App() {
  const dispatch=useDispatch()
  let {setAdmin}=adminSlice.actions
  useEffect(()=>{
    if(sessionStorage.getItem('loginId')){
      let loginId=sessionStorage.getItem('loginId');
      $getOne({loginId}).then(admin=>{
        dispatch(setAdmin(admin))
      })
    }
  })
  return (
    <BrowserRouter>
      <Routes>
        <Route path='/' element={<Login/>}/>
        <Route path='/layout' element={<Layout/>}>
          <Route path='role' element={<Role/>}/>
          <Route path='admin' element={<Admin/>}/>
          <Route path='mine' element={<Mine/>}/>
          <Route path='pwd' element={<UpdatePwd/>}/>
          <Route path='type' element={<Type/>}/>
          <Route path='room' element={<Room/>}/>
          <Route path='guest' element={<Guest/>}/>
          <Route path='total' element={<TotalPrice/>}/>
        </Route>
      </Routes>
    </BrowserRouter>
  );
}

export default App;
